package com.example.tencentdemo.service.Impl;

import com.tencentcloudapi.common.Credential;
import com.tencentcloudapi.common.profile.ClientProfile;
import com.tencentcloudapi.common.profile.HttpProfile;
import com.tencentcloudapi.common.exception.TencentCloudSDKException;
import com.tencentcloudapi.faceid.v20180301.FaceidClient;
import com.tencentcloudapi.faceid.v20180301.models.*;
import org.springframework.stereotype.Service;

@Service
public class identity {
    // private final String secretId = "AKIDtgauFOK1XxFKNVbWEj26CF7lqneODBCM";
    private final String secretId = " ";
    // private final String secretKey = "Skw1zjI0jaAh7W8theU8qmuERULzZ4kN";
    private final String secretKey = " ";
    Credential cred = new Credential(secretId, secretKey);

    public String ManualInput(String IdCard, String Name, String ImgBase64) throws TencentCloudSDKException {

        // 实例化一个http选项，可选的，没有特殊需求可以跳过
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("faceid.tencentcloudapi.com");
        // 实例化一个client选项，可选的，没有特殊需求可以跳过
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        // 实例化要请求产品的client对象,clientProfile是可选的
        FaceidClient client = new FaceidClient(cred, "", clientProfile);
        // 实例化一个请求对象,每个接口都会对应一个request对象
        ImageRecognitionV2Request req = new ImageRecognitionV2Request();
        req.setIdCard(IdCard);
        req.setName(Name);
        req.setImageBase64(ImgBase64);
        // 返回的resp是一个ImageRecognitionV2Response的实例，与请求对象对应
        ImageRecognitionV2Response resp = client.ImageRecognitionV2(req);
        // 输出json格式的字符串回包
        return ImageRecognitionV2Response.toJsonString(resp);
    }

    public String IdentifyInput(String ImgBase64) throws TencentCloudSDKException {
        // 实例化一个http选项，可选的，没有特殊需求可以跳过
        HttpProfile httpProfile = new HttpProfile();
        httpProfile.setEndpoint("faceid.tencentcloudapi.com");
        // 实例化一个client选项，可选的，没有特殊需求可以跳过
        ClientProfile clientProfile = new ClientProfile();
        clientProfile.setHttpProfile(httpProfile);
        // 实例化要请求产品的client对象,clientProfile是可选的
        FaceidClient client = new FaceidClient(cred, "", clientProfile);
        // 实例化一个请求对象,每个接口都会对应一个request对象
        CheckIdCardInformationRequest req = new CheckIdCardInformationRequest();
        req.setImageBase64(ImgBase64);
        CheckIdCardInformationResponse resp = client.CheckIdCardInformation(req);
        // 输出json格式的字符串回包
        System.out.println(CheckIdCardInformationResponse.toJsonString(resp));
        return CheckIdCardInformationResponse.toJsonString(resp);
    }


}
